import http from '@/utils/request'
import { setTokenInfo } from '@/utils/storage'
import { AppDispatch } from '..'
/**
 * 获取验证码
 * @param mobile 手机号码
 * @returns
 */
export const getCodes = (mobile: string) => {
  return (dispatch: AppDispatch) => {
    http.get(`/v1_0/sms/codes/${mobile}`)
  }
}
/**
 * 获取token
 * @param mobile 手机号码
 * @param code 验证码
 * @returns
 */
export const getToken = ({
  mobile,
  code,
}: {
  mobile: string
  code: string
}) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post(`/v1_0/authorizations`, { mobile, code })
    // console.log(res)
    dispatch({ type: 'user/setToekn', payload: res.data })
    setTokenInfo(res.data)
  }
}
